﻿@model Microsoft.EntityFrameworkCore.IPagedList
@{
    var windowSize = 4;
    var firstPage = Model.PageIndex - windowSize < 1 ? 1 : Model.PageIndex - windowSize;
    var lastPage = Model.PageIndex + windowSize > Model.TotalPages ? Model.TotalPages : Model.PageIndex + windowSize;
}

<div style="clear:both; display:block">
    @if (Model.TotalPages != 0)
    {
        <ul id="PostPager">
            @if (Model.PageIndex != 1)
            {
                <li class="PagerLink">
                    <a asp-controller="@ViewBag.ControllerName" asp-action="Pager" asp-route-id="@ViewBag.Id" asp-route-page="1" aria-label="首页">首页</a>
                </li>
            }
            @if (firstPage - 10 > 1)
            {
                <li class="PagerLink">
                    <a asp-controller="@ViewBag.ControllerName" asp-action="Pager" asp-route-id="@ViewBag.Id" asp-route-page="@(firstPage - 1)" aria-label="上一页">&larr; 上一页</a>
                </li>
            }
            @for (int x = firstPage; x < Model.PageIndex; ++x)
            {
                <li class="PagerLink">
                    <a asp-controller="@ViewBag.ControllerName" asp-action="Pager" asp-route-id="@ViewBag.Id" asp-route-page="@x">@x</a>
                </li>
            }
            <li class="PagerLinkCurrent">@Model.PageIndex</li>
            @for (int x = Model.PageIndex + 1; x <= lastPage; ++x)
            {
                <li class="PagerLink">
                    <a asp-controller="@ViewBag.ControllerName" asp-action="Pager" asp-route-id="@ViewBag.Id" asp-route-page="@x">@x</a>
                </li>
            }
            @if (Model.PageIndex < Model.TotalPages)
            {
                <li class="PagerLink">
                    <a aria-label="下一页" asp-controller="@ViewBag.ControllerName" asp-action="Pager" asp-route-id="@ViewBag.Id" asp-route-page="@(lastPage + 1)">下一页&rarr;</a>
                </li>

                <li class="PagerLink">
                    <a aria-label="尾页" asp-controller="@ViewBag.ControllerName" asp-action="Pager" asp-route-id="@ViewBag.Id" asp-route-page="@Model.TotalPages">尾页</a>
                </li>
            }
        </ul>

    }
</div>
